package attori.attuatori;

import gui.houseeditor.HouseModel;
import gui.houseeditor.HouseModel.HouseObject;
import sde.actor.Actor;
import sde.actor.Message;
import util.Casella;

public class AttuatorePorta extends Actor implements AttuatorePortaIF {
	public static final byte CREATED = 0, APERTA = 1, CHIUSA = 2;
	private HouseModel model;
	private Casella[] loco;

	public AttuatorePorta() {
		become(CREATED);
	}

	@Override
	protected void handler(Message m) {
		switch (currentStatus()) {
		case CREATED:
			if (m instanceof Init) {
				model = ((Init) m).model;
				loco = ((Init) m).loco;
				become(CHIUSA);
			}
			break;
		case CHIUSA:
			if (m instanceof ToOpen) {
				model.setCell(HouseObject.BLANK, loco[0].getX(), loco[0].getY());
				model.setCell(HouseObject.BLANK, loco[1].getX(), loco[1].getY());
				become(APERTA);
			}
			break;
		case APERTA:
			if (m instanceof ToClose) {
				model.setCell(HouseObject.PORTA, loco[0].getX(), loco[0].getY());
				model.setCell(HouseObject.PORTA, loco[1].getX(), loco[1].getY());
				become(CHIUSA);
			}
			break;
		}
	}

}
